import logging
from sqlalchemy.orm import Session
from schemas import Activity
from sql_app.models import *
from typing import Sequence
from . base import CrudBase
logger = logging.getLogger("crud")


class CrudActivity(CrudBase):

    @staticmethod
    def hook(db: Session, data: Sequence[Activity]):
        for activity in data:
            for each in activity.related_item:
                key, related_item_list = each

                for related_item in related_item_list:
                    if key == "questionnaire":
                        name = crud_questionnaire.get_name_by_id(db, related_item.id)
                        related_item.name = name if name is not None else ""
                    elif key == "vote":
                        name = crud_vote.get_name_by_id(db, related_item.id)
                        related_item.name = name if name is not None else ""
                    elif key == "lottery":
                        name = crud_lottery.get_name_by_id(db, related_item.id)
                        related_item.name = name if name is not None else ""


class CrudQuestionnaire(CrudBase):

    ...


class CrudQuestion(CrudBase):

    ...


class CrudVote(CrudBase):

    ...


class CrudVoteParticipant(CrudBase):

    ...


class CrudLottery(CrudBase):

    ...


crud_activity = CrudActivity(TActivity)
crud_questionnaire = CrudQuestionnaire(TActivityQuestionnaire)
crud_question = CrudActivity(TActivityQuestionnaireQuestion)

crud_vote = CrudVote(TActivityVote)
crud_vote_participant = CrudVoteParticipant(TActivityVoteParticipant)
crud_lottery = CrudVote(TActivityLottery)
